package dhk;

import static org.junit.Assert.*;
import org.junit.Test;

/**
 * Junit TestMovementUtility.
 * 
 * @author Dean Kim
 * 
 */
public class TestMovementUtility {

  /**
   * Tests computation of battlefield midpoint along the x axis.
   */
  @Test
  public void testComputeBattleFieldCenterX() {
    assertEquals("Check X Battlefield Midpoint 800",
        MovementUtility.computeBattleFieldCenterX(800), 400, 0);
    assertEquals("Check X Battlefield Midpoint 825",
        MovementUtility.computeBattleFieldCenterX(825), 412.5, 0);
  }

  /**
   * * Tests computation of battlefield midpoint along the y axis.
   */
  @Test
  public void testComputeBattleFieldCenterY() {
    assertEquals("Check X Battlefield Midpoint 800",
        MovementUtility.computeBattleFieldCenterX(800), 400, 0);
    assertEquals("Check X Battlefield Midpoint 825",
        MovementUtility.computeBattleFieldCenterX(825), 412.5, 0);
  }

  /**
   * Tests computed rotation from a given heading to a bearing.
   * 
   * Junit test method.
   */
  @Test
  public void testComputeRotationToBearing() {
    double rotation = 0;

    rotation = MovementUtility.computeRotationToBearing(0, 0);
    assertEquals("Check 0 to 0", rotation, 0, 0);
    rotation = MovementUtility.computeRotationToBearing(0, 179);
    assertEquals("Check 0 to 179", rotation, 179, 0);
    rotation = MovementUtility.computeRotationToBearing(0, 359);
    assertEquals("Check 0 to -1", rotation, -1, 0);
    rotation = MovementUtility.computeRotationToBearing(350, 10);
    assertEquals("Check 20 to 0", rotation, 20, 0);
    rotation = MovementUtility.computeRotationToBearing(350, 171);
    assertEquals("Check -170 to 0", rotation, -179, 0);

    // fail("Not yet implemented");
  }

  /**
   * Tests converting a relative to a true bearing. Junit test method.
   */
  @Test
  public void testConvertRelativeToTrueBearing() {
    assertEquals("Chk Brg 0 to 0", MovementUtility.convertRelativeToTrueBearing(0, 0), 0, 0);
    assertEquals("Chk Brg 0 to 10", MovementUtility.convertRelativeToTrueBearing(0, 10), 10, 0);
    assertEquals("Chk Brg 10 to 0", MovementUtility.convertRelativeToTrueBearing(10, 0), 10, 0);
    assertEquals("Chk Brg 10 to 1", MovementUtility.convertRelativeToTrueBearing(10, 1), 11, 0);
    assertEquals("Chk Brg 10 to 350", MovementUtility.convertRelativeToTrueBearing(10, 350), 0, 0);
    assertEquals("Chk Brg 10 to 359", MovementUtility.convertRelativeToTrueBearing(10, 359), 9, 0);
    // fail("Not yet implemented");
  }

  /**
   * Tests rotation to an XY position.
   * 
   * Junit test method.
   */
  @Test
  public void testComputeRotationToPosit() {
    double rotation = 0;

    rotation = MovementUtility.computeRotationToPosit(10, 10, 0, 100, 10);
    assertEquals("Chk from 0 and rotate 90 deg", rotation, 90, 0);
    rotation = MovementUtility.computeRotationToPosit(10, 10, 0, 20, 20);
    assertEquals("Chk from 0 and rotate 45 deg", rotation, 45, 0.0001);
    rotation = MovementUtility.computeRotationToPosit(10, 10, 0, 10, 0);
    assertEquals("Chk from 0 and rotate 180 deg", rotation, 180, 0.0001);
    rotation = MovementUtility.computeRotationToPosit(10, 10, 0, 0, 10);
    assertEquals("Chk from 0 and rotate -90 deg", rotation, -90, 0.0);
    rotation = MovementUtility.computeRotationToPosit(10, 10, 270, 20, 20);
    assertEquals("Chk from 270 and rotate 135 deg", rotation, 135, 0.0);
    rotation = MovementUtility.computeRotationToPosit(10, 10, 270, 0, 0);
    assertEquals("Chk from 270 and rotate -45 deg", rotation, -45, 0.0001);
  }

}
